package com.class05.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/13 16:50
 */
public class MyInterceptor implements HandlerInterceptor {
//    执行handler之前！调用的拦截方法
//    编码格式设置。登录保护。权限处理

    /**
     * @param request  请求对象
     * @param response 响应对象
     * @param handler  handler就是我们要调用的方法对象
     * @return true 放行  false拦截
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        System.out.println(handler);
        System.out.println("MyInterceptor.preHandle11111");
        return true;
    }

    /**
     * 当handler执行完毕后，出发的方法！没有拦截机制了
     * 此方法preHandle return true 才会走此方法
     * 对结果处理！ 敏感词汇检查！！！！
     *
     * @param request 请求
     * @param response 响应
     * @param handler handler方法
     * execution, for type and/or instance examination
     * @param modelAndView 返回的视图和共享域数据对象
     * (can also be {@code null})
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("MyInterceptor.postHandle2222222");
    }

    /**
     *
     * @param request current HTTP request
     * @param response current HTTP response
     * @param handler the handler (or {@link HandlerMethod}) that started asynchronous
     * execution, for type and/or instance examination
     * @param ex handler报错了 异常对象
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("MyInterceptor.afterCompletion33333333");
    }
}
